package {
	import dk.dashboardFP.dfpLogger.DFPLoggerLevels;
	import dk.dashboardFP.DashboardFP;
	import dk.dashboardFP.DashboardFPEvent;
	import dk.dashboardFP.dfpLogger.DFPLogger;
	import dk.dashboardFP.dfpLogger.logReceivers.ThunderBoltReceiver;

	import flash.display.Sprite;

	/**
	 * @author jk
	 */
	public class Example extends Sprite {
		
		private static const DATA_CALLS : int = 1;
		private static const MEDIA_PLAYBACK : int=2;
		
		/*
		 * Register DashboardFP
		 */
		public function Example() {
			
			// register DashboardFP ready-event
			DashboardFP.getInstance().addEventListener(DashboardFPEvent.DFP_READY, onDashboardReady);
			
			// Register dfp by passing parameters : stage, path for the core-swf, and the word that you wish to use for toggeling dfp on/off.
			// When this is done you can enable DashboardFP by typing you toggle-word followed by ENTER.
			DashboardFP.getInstance().registerDashboardFP(stage, "DFPCore.swf", "dfp");
		}

		/*
		 * The DFP_READY event will be dispatched regardless of dfp is enabled og disabled.
		 * This means that you can use this point for continuing your application instanciation.
		 */ 
		private function onDashboardReady(event : DashboardFPEvent) : void {
			setupLogging();
		}
		
		/*
		 * You can configure your logger-groups with the formatGroup method.
		 * This allows you to seperate and filter all your application logs.
		 * 
		 * Register log receivers to have all logs passed on to externel loggers like Thunderbold og Monsterdebugger.
		 */
		private function setupLogging() : void {
			DFPLogger.formatGroup(DATA_CALLS, "Data calls", 0x00FFFF);
			DFPLogger.formatGroup(MEDIA_PLAYBACK, "Media Playback", 0xFFFF00);
			
			DFPLogger.addLogReceiver(new ThunderBoltReceiver());
			
			logExamples();
		}
		
		/*
		 * DFPLogger can be used with diffrent levels of detail. Here are som examples:
		 */
		private function logExamples() : void {
			
			// simple trace 
			DFPLogger.log("Hello World");
			
			// trace with object for introspection - alows you to see the public properties of a given object
			var testObj:Object={prop1:"Prop 1 value", prop2:4, prop3:[1, 2, 3, 4, 5]};
			DFPLogger.log("Dynamic object data", testObj);
			
			// A third parameter can be set to bind a log to a specific group.
			DFPLogger.log("User data loaded", userData, DATA_CALLS);
			
			// To seperate logs in different levels a fourth parameter can be passed. Use the DFPLoggerLevel-constants for this. (INFO, DEBUG, WARN, ERROR)
			DFPLogger.log("User data failed", error, DATA_CALLS, DFPLoggerLevels.ERROR); 
			
			
			// Besides the main log-method there are a couple of others for more specific purposes.
			
			// This will auto-open an introspection window with the data-object and a predefined search for "image_gallery"
			DFPLogger.inspect("Image gallery data", data, DATA_CALLS, "image_gallery", true);
			
			// This will auto-open an introspection window with a hierarchal view of the displayChain descending from the '_galleryContainer' 
			DFPLogger.inspectDisplayChain("Gallery structure", _galleryContainer, -1, "", true);
			
			// The logStack method is a way of force a stack-trace silar to what appears in the error dialog of the debug-player.
			// It is handy to see the exact method-chain preceding the method from where the logStack is called.
			DFPLogger.logStack();
			
		}
	}
}
